<?php if (!defined('THINK_PATH')) exit();?><style>
    .pageFormContent p{
        float:none;
    }



    .yuns label{
        width:auto;
        padding:0px 10px;
    }

    .pageFormContent .textInput{
        width:40px;
        float:none;
    }

    .pageFormContent p{
        width:auto;
    }

    ._citys {    display:none; background: #fff;width: 450px; z-index:1000;display: inline-block; border: 2px solid #eee; padding: 5px; position: relative; }
    ._citys span { color: #56b4f8; height: 15px; width: 15px; line-height: 15px; text-align: center; border-radius: 3px; position: absolute; right: 10px; top: 10px; border: 1px solid #56b4f8; cursor: pointer; }
    ._citys0 { width: 100%; height: 34px; display: inline-block; border-bottom: 2px solid #56b4f8; padding: 0; margin: 0; }
    ._citys0 li { display: inline-block; line-height: 34px; font-size: 15px; color: #888; width: 80px; text-align: center; cursor: pointer; }
    .citySel { background-color: #56b4f8; color: #fff !important; }
    ._citys1 { width: 100%; display: inline-block; padding: 10px 0; }
    ._citys1 a { width: 83px; height: 35px; display: inline-block; background-color: #f5f5f5; color: #666; margin-left: 6px; margin-top: 3px; line-height: 35px; text-align: center; cursor: pointer; font-size: 13px; overflow: hidden; }
    ._citys1 a:hover { color: #fff; background-color: #56b4f8; }
    .AreaS { background-color: #56b4f8 !important; color: #fff !important; }


</style>
<script src="js/jquery-2.1.4.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/swfupload.js"></script>
<script type="text/javascript" src="js/handlers.js"></script>
<link href="css/default.css" rel="stylesheet" type="text/css" />
<div class="pageContent">

    <form method="post" action="index.php?c=Goods&a=update" class="pageForm required-validate" >
    <input type="text" name="s" id="" value="" class="imgName" />
    <input type="text" name="s1" id="" value="" class="imgName" />
    <input type="text" name="goodsid" id="goodsid" value="<?php echo ($goods["goodsid"]); ?>">

        <div class="pageFormContent" layoutH="56">
            <div style="padding-bottom:20px;border-bottom:1px solid #eaeaea">添加商品:</div>
            <p>
                <label>商品名称：</label>
                <input name="title" type="text" size="50" class="required" style="width:150px;" value="<?php echo ($goods["title"]); ?>"/>
            </p>

            <p>
                <label>是否上架：</label>
                <?php if($goods['shangjia'] == 0): ?><input type="radio" name="shangjia" value="0" checked="checked" class="isP"/>否
                    <input type="radio" name="shangjia" value="1" class="isP"/>是
                <?php else: ?>
                    <input type="radio" name="shangjia" value="0"  class="isP"/>否
                    <input type="radio" name="shangjia" value="1" checked="checked" class="isP"/>是<?php endif; ?>

<!--                 <input type="radio" name="shangjia" value="0" checked="checked" class="isP"/>否
                <input type="radio" name="shangjia" value="1" class="isP"/>是 -->
            </p>
			
            <p>
                <label>价格：</label>
                <input name="price" type="text" size="30" class="required" style="width:100px;" value="<?php echo ($goods["price"]); ?>" />
            </p>

            <p>
                <label>原价：</label>
                <input name="yuanjia" type="text" size="30" class="required" style="width:100px;" value="<?php echo ($goods["yuanjia"]); ?>"/>
            </p>

            <p>
                <label>起批量：</label>
                <input name="start_num_desc" type="text" size="30" class="required" style="width:150px;" placeholder="输入数量" value="<?php echo ($goods["start_num"]); ?>" />
                <input name="start_num" type="text" size="30" class="required" style="width:150px;"  placeholder="输入单位" value="<?php echo ($goods["start_num_desc"]); ?>"/>
            </p>
			
            <p>
                <label>简介：</label>
				<textarea name="summary" cols="20" class="required" rows="5" style="width: 400px; height: 200px;"><?php echo ($goods["summary"]); ?></textarea>
            </p>

            <p style="margin-top: 100px;">
                <label>商品主图：</label>
                <div style="width: 610px; height: auto; border: 1px solid #e1e1e1; font-size: 12px; padding: 10px;">
                    <span id="spanButtonPlaceholder1"></span>
                    <div id="divFileProgressContainer1"></div>
                    <div id="thumbnails">
                        <ul id="pic_list1" style="margin: 5px;"></ul>
                        <div style="clear: both;"></div>
                    </div>
                </div>
            </p>

            <p style="margin-top: 100px;">
                <label>商品详情图：</label>
                <div style="width: 610px; height: auto; border: 1px solid #e1e1e1; font-size: 12px; padding: 10px;">
                    <span id="spanButtonPlaceholder2"></span>
                    <div id="divFileProgressContainer2"></div>
                    <div id="thumbnails">
                        <ul id="pic_list2" style="margin: 5px;"></ul>
                        <div style="clear: both;"></div>
                    </div>
                </div>
            </p>

            <p style="margin-top: 50px;">
                <label>商家：</label>
                    <select name="shopid" onchange="zileimu(this.value)">
                        <option value="<?php echo ($moren_shopid["shopid"]); ?>" selected="true"><?php echo ($moren_shopid["name"]); ?></option>
                    <?php if(is_array($shop)): foreach($shop as $key=>$shop): ?><option  value="<?php echo ($shop["shopid"]); ?>"><?php echo ($shop["name"]); ?></option><?php endforeach; endif; ?>
                    </select>
            </p>

            <p>
                <label>运费模板：</label>
                        <select name="muid">
                            <option value ="<?php echo ($faremlid["id"]); ?>"><?php echo ($faremlid["name"]); ?></option>
                        <?php if(is_array($fareml)): foreach($fareml as $key=>$fareml): ?><option value ="<?php echo ($fareml["id"]); ?>"><?php echo ($fareml["name"]); ?></option><?php endforeach; endif; ?>
                        </select>
            </p>

            <p>
                <label>子分类：</label>
                        <select name="zixilie" id="zixilie">
                        <?php if(is_array($zileimu)): foreach($zileimu as $key=>$zileimu): ?><option value ="<?php echo ($zileimu["id"]); ?>"><?php echo ($zileimu["name"]); ?></option><?php endforeach; endif; ?>
                        </select>
            </p>

            <p>
                <label>支持返券：</label>
                <?php if($goods['can_fanquan'] == 0): ?><input type="radio" name="can_fanquan" value="0" checked="checked" class="isP"/>否
                <input type="radio" name="can_fanquan" value="1" class="isP"/>是
                <?php else: ?>
                <input type="radio" name="can_fanquan" value="0" class="isP"/>否
                <input type="radio" name="can_fanquan" value="1" checked="checked" class="isP"/>是<?php endif; ?>
            </p>

            <p>
                <label>猜你喜欢：</label>
                <?php if($goods['xihuan'] == 0): ?><input type="radio" name="xihuan" value="0" checked="checked" class="isP"/>关闭
                <input type="radio" name="xihuan" value="1"  class="isP"/>开启
                <?php else: ?>
                <input type="radio" name="xihuan" value="0" class="isP"/>关闭
                <input type="radio" name="xihuan" value="1" checked="checked" class="isP"/>开启<?php endif; ?>
            </p>

            <p>
                <label>特价：</label>
                <?php if($goods['tejia'] == 0): ?><input type="radio" name="tejia" value="0" checked="checked" class="isP"/>关闭
                <input type="radio" name="tejia" value="1" class="isP"/>开启
                <?php else: ?>
                <input type="radio" name="tejia" value="0" class="isP"/>关闭
                <input type="radio" name="tejia" value="1" checked="checked" class="isP"/>开启<?php endif; ?>
            </p>

            <p>
                <label>扫货：</label>
                <?php if($goods['act_saohuo'] == 0): ?><input type="radio" name="act_saohuo" value="0" checked="checked" class="isP"/>关闭
                <input type="radio" name="act_saohuo" value="2" class="isP"/>开启
                <?php else: ?>
                <input type="radio" name="act_saohuo" value="0" class="isP"/>关闭
                <input type="radio" name="act_saohuo" value="2" checked="checked" class="isP"/>开启<?php endif; ?>
            </p>

            <p>
                <label>限时折扣：</label>
                <?php if($goods['act_xianshizhekou'] == 0): ?><input type="radio" name="act_xianshizhekou" value="0" checked="checked" class="isP"/>关闭
                <input type="radio" name="act_xianshizhekou" value="2"  class="isP"/>开启
                <?php else: ?>
                <input type="radio" name="act_xianshizhekou" value="0" class="isP"/>关闭
                <input type="radio" name="act_xianshizhekou" value="2" checked="checked" class="isP"/>开启<?php endif; ?>
            </p>

            <p>
                <label>首选精品：</label>
                <?php if($goods['act_shouxuanjingpin'] == 0): ?><input type="radio" name="act_shouxuanjingpin" value="0" checked="checked" class="isP"/>关闭
                <input type="radio" name="act_shouxuanjingpin" value="2" class="isP"/>开启
                <?php else: ?>
                <input type="radio" name="act_shouxuanjingpin" value="0" class="isP"/>关闭
                <input type="radio" name="act_shouxuanjingpin" value="2" checked="checked" class="isP"/>开启<?php endif; ?>
            </p>

            <p>
                <label>你想要的：</label>
                <?php if($goods['act_shouxuanjingpin'] == 0): ?><input type="radio" name="act_nixiangyaode"  value="0" checked="checked" class="isP"/>关闭
                <input type="radio" name="act_nixiangyaode" value="2" class="isP"/>开启
                <?php else: ?>
                <input type="radio" name="act_nixiangyaode"  value="0" class="isP"/>关闭
                <input type="radio" name="act_nixiangyaode" value="2" checked="checked"  class="isP"/>开启<?php endif; ?>
            </p>
			
			<div>
            <p>
            	<label>规格：</label>
            	<div class="parents">
                    
                </div>
	            <a onclick="add_main_class()" >添加</a>
            </p>
			</div>

        </div>
        <div class="formBar">
            <ul>
                <li>
	                <div class="buttonActive">
		                <div class="buttonContent">
		                	<button type="submit">保存</button>
		                </div>
	                </div>
                </li>
                <li>
                    <div class="button">
	                    <div class="buttonContent">
	                    	<button type="button" class="close">取消</button>
	                    </div>
                    </div>
                </li>
            </ul>
        </div>
    </form>
</div>
<!-- <script src="js/jquery-2.1.4.min.js" type="text/javascript"></script> -->
<script>
   var i = -1;
   var j = -1;
    function add_main_class() {
    	i++;
    	var num = Math.floor(Math.random()*100);
  		var html = "";
			html += "<div class='dad" + num + "'>";
			html += "名字<input name='guige["+ num +"][fTitle]' type='text' size='30' class='required' style='width:150px;'  placeholder='输入单位' value='' id='ftitle" + num + "' />";
			html += "价格<input name='guige["+ num +"][price]' type='text' size='30' class='required' style='width:150px;'  placeholder='输入单位' value='' id='ftitle" + num + "' />";
			html += "数量<input name='guige["+ num +"][number]' type='text' size='30' class='required' style='width:150px;'  placeholder='输入单位'/>";
			html += "<a onclick='removeDiv("+ num +")' >删除</a>";
			html += "<a onclick='add_son("+ num +")' >添加子类</a>";
			html += "</div>";
		$('.parents').append(html);
    }

    function add_son(num) {
    	var name = '.dad' + num;
    	var ftitle = '#ftitle' + num;
    	j++;

		var html = "";
		if($(name).find("div").length>0){
			var val = $(ftitle).val(); //获取
			if(val == '') {
				alert("请输入名字,在添加子类");
			} else {
	    		html += "<div class='son"+ num +"' style='margin-left:50px; margin-top:10px;'>";
	   		    html += "<input name='guige["+ j +"][fTitle]' type='hidden' size='30' class='required' style='width:150px;'  placeholder='输入单位' value='" + val + "'/>";
				html += "子类<input name='guige["+ j +"][sTitle]' type='text' size='30' class='required' style='width:150px;'  placeholder='输入单位'/>";	
				html += "价格<input name='guige["+ j +"][price]' type='text' size='30' class='required' style='width:150px;'  placeholder='输入单位'/>";
				html += "数量<input name='guige["+ j +"][number]' type='text' size='30' class='required' style='width:150px;'  placeholder='输入单位'/>";
				html += "<a onclick='removeDiv("+ num +")' >删除</a>";
				html += "</div>";
				$(name).append(html);
			}

		} else {
		    // html += "<div class='dad" + num + "'>";
		    html += "名字<input name='guige["+ j +"][fTitle]' type='text' size='30' class='required' style='width:150px;'  placeholder='输入单位' value='' id='ftitle" + num + "' />";
		    html += "<a onclick='add_son("+ num +")' >添加子类</a>";
    		html += "<div class='son"+ num +"' style='margin-left:50px;'>";
			html += "子类<input name='guige["+ j +"][sTitle]' type='text' size='30' class='required' style='width:150px;'  placeholder='输入单位' />";	
			html += "价格<input name='guige["+ j +"][price]' type='text' size='30' class='required' style='width:150px;'  placeholder='输入单位'/>";
			html += "数量<input name='guige["+ j +"][number]' type='text' size='30' class='required' style='width:150px;'  placeholder='输入单位'/>";
			// html += "ID<input  type='text' size='30' class='required' style='width:150px;'  value='111'/>";
			html += "<a onclick='removeDiv("+ num +")' >删除</a>";
			html += "</div>";
		    // html += "</div>";
		    $(name).html(html);
		}
    }

	function removeDiv(num, selectid){
        if(selectid) {
            $.ajax({
              type:"POST",
              async: false,
              url: "index.php?c=Goods&a=del_guige",
              data: {"selectid":selectid},
              dataType:'json',
              success:function(data){

                }
            });
        }
		var name = '.dad' + num;
	 	$(name).remove();

	}

    $(document).ready(function(){ 
        var goodsid = $("#goodsid")[0].value; 

        $.ajax({
          type:"POST",
          url: "index.php?c=Goods&a=get_guige",
          data: {"goodsid":goodsid, "type":1},
          dataType:'json',
          success:function(data){
            var html = "";
            if(data['guige_dad'] == null && data['guige_son'] == null) {
                return false;
            }

            for(i=0;i<data['guige_dad'].length;i++) {
                var num = Math.floor(Math.random()*100);
                html += "<div class='dad" + num + "'>";
                html += "名字<input name='guige[fTitle]' type='text' size='30' class='required' style='width:150px;' value='" + data['guige_dad'][i]['fTitle'] +"' id='ftitle" + num + "' />";
                html += "<a onclick='add_son("+ num +")' >添加子类</a>";

                for(j=0;j<data['guige_son'].length;j++) {

                    if(data['guige_dad'][i]['fTitle'] == data['guige_son'][j]['fTitle']) {
                        html += "<div class='son"+ num +"' style='margin-left:50px;'>";
                        html += "<input name='guige["+ j +"][fTitle]' type='hidden' size='30' class='required' style='width:150px;' value='" + data['guige_dad'][i]['fTitle'] +"' id='ftitle" + num + "' />";
                        html += "<input name='guige["+ j +"][selectid]' type='hidden' size='30' class='required' style='width:150px;' value='" + data['guige_son'][j]['selectid'] +"' id='ftitle" + num + "' />";
                        html += "子类<input name='guige["+ j +"][sTitle]' type='text' size='30' class='required' style='width:150px;' value='" + data['guige_son'][j]['sTitle'] + "'/>";    
                        html += "价格<input name='guige["+ j +"][price]' type='text' size='30' class='required' style='width:150px;' value='" + data['guige_son'][j]['price'] + "'/>";
                        html += "数量<input name='guige["+ j +"][number]' type='text' size='30' class='required' style='width:150px;' value='" + data['guige_son'][j]['number'] + "'/>"; 
                        html += "<a onclick='removeDiv("+ num +","+ data['guige_son'][j]['selectid'] + ")' >删除</a>";
                        html += "</div>";
                    }
                }
                html += "</div>";
                $('.parents').html(html);
            }
          }
        });
    });

    function zileimu(shopid) {
        $.ajax({
          type:"POST",
          async: false,
          url: "index.php?c=Goods&a=zifenlei",
          data: {"shopid":shopid},
          dataType:'json',
          success:function(data){
                var html = '';
                for(i=0;i<data.length;i++) {
                    html += "<option value =" + data[i]['id'] + ">"+ data[i]['name'] +"</option>";
                }
                $('#zixilie').html(html);
            }
        });
    }
</script>
<script type="text/javascript">
        var swfu1;
        var swfu2;
        $(document).ready(function(){ 
                swfu1 = new SWFUpload({
                    upload_url: "index.php?c=Goods&a=uploadImg",
                    post_params: {"PHPSESSID": "<?php echo session_id();?>"},
                    file_size_limit : "2 MB",
                    file_types : "*.jpg;*.png;*.gif;*.bmp",
                    file_types_description : "JPG Images",
                    file_upload_limit : "100",
                    file_queue_error_handler : fileQueueError,
                    file_dialog_complete_handler : fileDialogComplete,
                    upload_progress_handler : uploadProgress,
                    upload_error_handler : uploadError,
                    upload_success_handler : uploadSuccess,
                    upload_complete_handler : uploadComplete,
                    button_image_url : "Public/images/upload.png",
                    button_placeholder_id : "spanButtonPlaceholder1",
                    button_width: 113,
                    button_height: 33,
                    button_text : '',
                    button_text_style : '.spanButtonPlaceholder { font-family: Helvetica, Arial, sans-serif; font-size: 14pt;} ',
                    button_text_top_padding: 0,
                    button_text_left_padding: 0,
                    button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
                    button_cursor: SWFUpload.CURSOR.HAND,           
                    flash_url : "swf/swfupload.swf",
                    custom_settings : {
                        upload_target : "divFileProgressContainer1",
                        // cancelButtonId : "btnCancel1"

                },              
                debug: false
            });

                swfu2 = new SWFUpload({
                    upload_url: "index.php?c=Goods&a=uploadImg",
                    post_params: {"PHPSESSID": "<?php echo session_id();?>"},
                    file_size_limit : "2 MB",
                    file_types : "*.jpg;*.png;*.gif;*.bmp",
                    file_types_description : "JPG Images",
                    file_upload_limit : "100",
                    file_queue_error_handler : fileQueueError,
                    file_dialog_complete_handler : fileDialogComplete,
                    upload_progress_handler : uploadProgress,
                    upload_error_handler : uploadError,
                    upload_success_handler : uploadSuccess,
                    upload_complete_handler : uploadComplete,
                    button_image_url : "Public/images/upload.png",
                    button_placeholder_id : "spanButtonPlaceholder2",
                    button_width: 113,
                    button_height: 33,
                    button_text : '',
                    button_text_style : '.spanButtonPlaceholder { font-family: Helvetica, Arial, sans-serif; font-size: 14pt;} ',
                    button_text_top_padding: 0,
                    button_text_left_padding: 0,
                    button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
                    button_cursor: SWFUpload.CURSOR.HAND,           
                    flash_url : "swf/swfupload.swf",
                    custom_settings : {
                        upload_target : "divFileProgressContainer2",
                        // cancelButtonId : "btnCancel2"

                },              
                debug: false
            });
        }); 
</script>
<script type="text/javascript">
$(function(){
    var id = $('#id').val();
    $(document).ready(function() {
            $.ajax({
              type:"POST",
              url: "index.php?c=Goods&a=get_img",
              data: {"id":id,},
              dataType:'json',
              success:function(array){
                    var html = "";
                    var html1 = ""; 
                    var img = "";
                    var img1 = "";
                        for(var i=0;i<array['images'].length;i++) {
                            var shu = i+1;
                            html += "<li style='margin-left:0px;'>";
                            html += "<img class='content' src='../" + array['images'][i] + "' style='width: 100px; height: 100px;'>";
                            html += "<img class='button1' src='Public/images/fancy_close.png'>";
                            html += "<input id='imgId' class='imgId" + shu + "' type='hidden' value='" + shu +"'>";
                            html += "</li>";
                            img += array['images'][i] + ',';
                        }

                        for(var i=0;i<array['xiangQingTu'].length;i++) {
                            var shu = i+1;
                            html1 += "<li style='margin-left:0px;'>";
                            html1 += "<img class='content' src='../" + array['xiangQingTu'][i] + "' style='width: 100px; height: 100px;'>";
                            html1 += "<img class='button2' src='Public/images/fancy_close.png'>";
                            html1 += "<input id='imgId' class='imgId" + shu + "' type='hidden' value='" + shu +"'>";
                            html1 += "</li>";
                            img1 += array['xiangQingTu'][i] + ',';
                        }

                        var images = img.substring(0,img.length-1)
                        var images1 = img1.substring(0,img.length-1)

                        $("#pic_list1").append(html);
                        $("#pic_list2").append(html1);

                        $("img.button1").bind("click", del1);
                        $("img.button2").bind("click", del2);
                        $('form>input[name=s]').val(images);
                        $('form>input[name=s1]').val(images);
                  }
              
            });
    });
});
</script>